<style>
.pageFormContent .inputArea p
{
float: none;
width:800px;
}

#inStock .lb
{
    width: 150px;
    left: 480px;
    position: absolute;
}

#inStock span.error {
    position: absolute !important;
    left: 260px;
}

</style>
<#include "/common/pagerForm.html">

<div class="pageContent">
    <div class="pageFormContent" id="inStock">
        <div class="inputArea">
        <form rel="pagerForm" method="post" action="" class="pageForm required-validate" >
            <p>
                <label><@label key="warehouse.C,colon">仓库：</@label></label> 
                <select onchange="inStockJs._wareChange(this)" id="in_warehouse" class="allyselect" ref="in_location;in_moveType" postField="warehousCode"
                refUrl="${rc.getContextPath()}/manage/inStock/warehouseChange" name="toWarehouseCode" class="required"> 
                <#list warehouses as warehouse>
                    <option flag="${warehouse.locationManageFlag}" value='${warehouse.warehouseCode}'<#if storageLocation.warehouseCode?? && storageLocation.warehouseCode == warehouse.warehouseCode> selected="selected"</#if>> ${warehouse.warehouseCode}-${warehouse.warehouseText}</option> </#list>
                </select> 
                <label class="lb"><input type="checkbox"  value="1"><@label key="resetWareHous.C">提交后重置仓库</@label></label>
            </p>
            <p id="storage">
                <label><@label key="storageLocation.C,colon">库位：</@label></label> 
                <select id="in_location" field="storageLocationCode" name="toLocationCode" label="storageLocationText" class="required"> 
                </select> 
                <label class="lb"><input type="checkbox"  value="1"><@label key="resetStorageLocation.C">提交后重置库位</@label></label>
            </p>
            <p>
                <label><@label key="moveType.C,colon">移动类型：</@label></label> 
                <select id="in_moveType" field="moveTypeCode"  name="moveTypeCode" label="moveTypeText" class="required"> 
                </select> 
                <label class="lb"><input type="checkbox"  value="1"><@label key="resetMoveType.C">提交后重置移动类型</@label></label>
            </p>
            <p>
                <label ><@label key="material.C,colon">物料：</@label></label>
                 <input class="required look" id="materialLookup.materialCode" name="materialCode" type="text" postField="materialCode" suggestFields="materialCode,materialText" suggestUrl="${rc.getContextPath()}/manage/material/componentSuggest" lookupGroup="materialLookup"  
                 warn="<@label key='materialCode.C,doesNotExist.C'>物料编号不存在</@label>"  remote="${rc.getContextPath()}/manage/material/validateMaterial"/>
                 <a class="btnLook" href="${rc.getContextPath()}/manage/material/componentLookUp?lookupType=radio" rel="materialLookup_dialog" title="<@label key='select.C,materialCode.C'>选择物料</@label>"  lookupGroup="materialLookup"></a> 
                <input style="margin-left: 15px;" id="materialLookup.materialText" name="materialText" type="text" readonly="readonly" /> 
                <label class="lb"><input type="checkbox" value="1"><@label key="resetMaterial.C">提交后重置物料</@label></label>
            </p>
            <p>
                <label><@label key='quantity.C,colon'>数量：</@label></label> 
                <input type="text" name="quantity" class="required digits integer" min="1" maxlength="15" /> 
                <label class="lb"><input type="checkbox" value="1" checked><@label key="resetQuantity.C">提交后重置数量</@label></label>
            </p>
            <p>
                <label><@label key="supplier.C,colon">供应商：</@label></label> 
                <input class="look" id="supplierLookup.supplierCode" name="supplierCode" type="text" postField="supplierCode" suggestFields="supplierCode,supplierText" suggestUrl="${rc.getContextPath()}/manage/supplier/supplierSuggest" lookupGroup="supplierLookup" 
                 warn="<@label key='supplier.C,doesNotExist.C'>供应商不存在</@label>"  remote="${rc.getContextPath()}/manage/supplier/validateSupplier"/> 
                <a class="btnLook" href="${rc.getContextPath()}/manage/supplier/supplierLookUp" rel="materialLookup_dialog" title="<@label key='select.C,supplier.C'>选择供应商</@label>" lookupGroup="supplierLookup"/></a> 
                <input style="margin-left: 15px;" id="supplierLookup.supplierText" name="supplierText" type="text" readonly="readonly" /> 
                <label class="lb"><input type="checkbox"  value="1"><@label key="resetSupplier.C">提交后重置供应商</@label></label>
            </p>
            <p>
                <label><@label key='lotNum.C,colon'>批次号：</@label></label> 
                <input type="text" name="lotNum" maxlength="40" /> 
                <label class="lb"><input type="checkbox" value="1"><@label key="resetLotNum.C">提交后重置批号</@label></label>
            </p>

            <div class="pageContent" style="padding: 5px 0;">
                        <ul>
                    <li>
            <div class="buttonActive" style="margin-left: 110px;">
                            <div class="buttonContent">
                                <button type="button" onclick="inStockJs._submit(this)"><@label key="inStock.B">入库</@label></button>
                            </div>
                        </div></li>
                        <li>
                        <div class="buttonActiveGrey" style="margin-left: 50px;">
                            <div class="buttonContent">
                                    <button type="reset" onclick='inStockJs._reset(this)'><@label key="reset.B">重置</@label></button>
                            </div>
                        </div>
                        </li></ul>
                        </div>
        </form>

            <p>
            <label style="width:108px"><@label key="opLog.C">操作日志：保留最近</@label></label>
            <input style="width:50px" value="100" id="count" size="22" type="text" min="1" maxlength="5" class=" integer number" 
            onkeypress="inStockJs._countKeypress(event)" onblur="inStockJs._countBlur()"/>
            <label><@label key="record.C">条记录</@label></label>
            </p>

            
    <table class="table border" width="100%" layoutH="330" style="overflow:scroll;">
        <thead>
            <tr>
                <th width="100" orderField="storageLocationCode"><@label key="material.C">物料</@label></th>
                <th width="100" orderField="storageLocationText"><@label key="warehouse.C">仓库</@label></th>
                <th width="100" orderField="warehouseText"><@label key="storageLocation.C">库位</@label></th>
                <th width="100" orderField="storageLocationTypeText"><@label key="quantity.C">数量</@label></th>
                <th width="100" orderField="storageLocationTypeText"><@label key="supplier.C">供应商</@label></th>
                <th width="100" orderField="storageLocationTypeText"><@label key="lotNum.C">批次号</@label></th>
                <th width="100" orderField="storageLocationTypeText"><@label key="opTime.C">操作时间</@label></th>
            </tr>
        </thead>
        <tbody id='tbody'>
            <tr target="resource_id">
                    <td colspan="7" class="noData">======<@label key="noListData.C">列表无数据</@label>=====</td>
            </tr>
        </tbody>
    </table>

        </div>
    </div>
    </div>


<script type="text/javascript">
Date.prototype.Format = function(fmt) { //author: meizz   
    var o = {
        "M+" : this.getMonth() + 1, //月份   
        "d+" : this.getDate(), //日   
        "h+" : this.getHours(), //小时   
        "m+" : this.getMinutes(), //分   
        "s+" : this.getSeconds(), //秒   
        "q+" : Math.floor((this.getMonth() + 3) / 3), //季度   
        "S" : this.getMilliseconds()
    //毫秒   
    };
    if (/(y+)/.test(fmt))
        fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "")
                .substr(4 - RegExp.$1.length));
    for ( var k in o)
        if (new RegExp("(" + k + ")").test(fmt))
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k])
                    : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}
var inStockJs = {
    _isFirst:true,
    _submit: function (t) {
        var $form = $(t).parents('form:first');
        if (!$form.valid()) {
            return false;
        }
        var d=$form.serializeArray();
        $.ajax({
            type:'POST',
            url:'${rc.getContextPath()}/manage/inStock/saveInStock',
            data:d,
            dataType:"json",
            cache: false,
            success: function(data){
                DWZ.ajaxDone(data);
                if (data.statusCode == DWZ.statusCode.ok) {
                    // 根据checkbox重置数据
                    $.each($('p > label > :checkbox', $form), function(){
                        if (this.checked) {
                            var $this = $(this), $p = $this.parent().parent();
                            $('select option:eq(0)', $p).attr('selected', 'selected').parent().change();
                            $('input[type=text]', $p).val('');
                        }
                    });
                    inStockJs._addLog(d);
                }
            },
            error: DWZ.ajaxError
        });
     },
     _wareChange:function(s)
     {
        var $this=$('>:selected', $(s));
        if($this.attr('flag')==0)
        {
            $('#storage',navTab.getCurrentPanel()).hide();
            $('#in_location',navTab.getCurrentPanel()).removeClass('required');
            $('.gridScroller', navTab.getCurrentPanel()).attr('layouth', 300);
        }
        else
        {
            $('#storage',navTab.getCurrentPanel()).show();
            $('#in_location',navTab.getCurrentPanel()).addClass('required');
            $('.gridScroller', navTab.getCurrentPanel()).attr('layouth', 331);
        }
        $(window).resize();
     },
     _reset:function(t)
     {
         var $form = $(t).parents('form:first');
            $.each($('p', $form), function(){
                var $p = $(this);
                $('select option:eq(0)', $p).attr('selected', 'selected').parent().change();
            });
     },
     _addLog:function(data)
     {
         var $tr = $('<tr/>');
         for(var i = 0; i < 7; i++) {
             $tr.append('<td/>');
         }
         $.each(data, function(){
             var key = this.name, value = this.value;
             if(key == 'materialCode') {
                 $('td:eq(0)', $tr).append(value)
             }else if(key == 'toWarehouseCode'){
                 $('td:eq(1)', $tr).append(value)
             }else if(key == 'toLocationCode'){
                 $('td:eq(2)', $tr).append(value)
             }else if(key == 'quantity'){
                 $('td:eq(3)', $tr).append(value)
             }else if(key == 'supplierCode'){
                 $('td:eq(4)', $tr).append(value)
             }else if(key == 'lotNum'){
                 $('td:eq(5)', $tr).append(value)
             }
         });
         $tbody=$('#tbody',navTab.getCurrentPanel());
         if(inStockJs._isFirst)
         {
             $tbody.empty(); 
             inStockJs._isFirst=false;
         }
         var mydate = new Date();
          var day = mydate.Format("yyyy-MM-dd hh:mm:ss");
         $('td:eq(6)', $tr).append(day)
         $tr.prependTo($tbody);
         var rowNums = parseInt($('#count',navTab.getCurrentPanel()).val()) || 100;
         if ($('tr', $tbody).length > rowNums) {
             $('tr:gt(' + (rowNums - 1) + ')', $tbody).remove();
         }
         $.jTableTool.initGridColumnWidth($tbody.parents('.grid:first'));
         if (!$('#count',navTab.getCurrentPanel()).val()) {
             $('#count',navTab.getCurrentPanel()).val(100);
         }
     },
     _countKeypress:function(event)
     {
         if(event.keyCode == "13")    
         {
             $tbody=$('#tbody',navTab.getCurrentPanel());
             var rowNums = parseInt($('#count',navTab.getCurrentPanel()).val()) || 100;
             if ($('tr', $tbody).length > rowNums) {
                 $('tr:gt(' + (rowNums - 1) + ')', $tbody).remove();
             }
         }
     },
     _countBlur:function()
     {
         $tbody=$('#tbody',navTab.getCurrentPanel());
         var rowNums = parseInt($('#count',navTab.getCurrentPanel()).val()) || 100;
         if ($('tr', $tbody).length > rowNums) {
             $('tr:gt(' + (rowNums - 1) + ')', $tbody).remove();
         }
     }
}
</script>
